package com.dtw.ditouwang.ui.mine;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.AssetsBean;
import com.dtw.ditouwang.repositories.UserRepository;
import com.dtw.ditouwang.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class AssetsActivty extends BaseActivity {
    public static final String KeyType = "KeyType";
    AssetsAdapter assetsAdapter;
    TextView type, amount;
    List<AssetsBean.DataBean.ListBean> assetsBeanlist = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_assets);
        enableBack();
        type = findViewById(R.id.text_type);
        amount = findViewById(R.id.text_amount);
        if (getIntent().getIntExtra(KeyType, 1) == 1) {
            type.setText("金币");
        } else {
            type.setText("体力");
        }
        RecyclerView recyclerView = findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        assetsAdapter = new AssetsAdapter(assetsBeanlist);
        recyclerView.setAdapter(assetsAdapter);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            getWindow().setStatusBarColor(ContextCompat.getColor(this, android.R.color.transparent));
        }

        webApi.getAssets(UserRepository.getInstance().getUserID(), getIntent().getIntExtra(KeyType, 1)).enqueue(new Callback<AssetsBean>() {
            @Override
            public void onResponse(Call<AssetsBean> call, Response<AssetsBean> response) {
                if (response.body().isResult()) {
                    amount.setText(response.body().getData().getAssets());
                    assetsBeanlist.clear();
                    assetsBeanlist.addAll(response.body().getData().getList());
                    assetsAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFailure(Call<AssetsBean> call, Throwable t) {

            }
        });

    }
}
